import app from '@/main'
import { API_FRONT, API, API4, API_SEARCH } from 'js/config'
import $http from 'js/request'

// 注册
export const apiRegister = (data) => {
  return $http.post(`${API}regist`, data)
}

// 登录
export const apiLogin = data => {
  return $http.post(`${API}login/login`, data)
}

// 发送短信验证码
export const apiSendMsg = (telphone) => {
  return $http.post(`${API}login/sendMsg`, { telphone: telphone })
}

// 当前用户所有地址列表
export const apiAddressAll = (accessToken, currentPage, showCount) => {
  return $http.post(`${API_FRONT}address/selectAddressAll`, { accessToken, currentPage, showCount })
}

// 获取区域
export const apiAreaAll = () => {
  return $http.post(`${API}area/selectAreaAll`, {})
}

// 找回密码
export const apiForgetPwd = (telphone, verificationCode, password) => {
  return $http.post(`${API}login/forgetPwd`, { telphone: telphone, verificationCode: verificationCode, password: password })
}

// 获取图片验证码
export const apiVerification = `${API}verification/`

// 验证图片验证码
export const apiCheckCode = (codeToken, code) => {
  return $http.get(`${API}checkCode/${codeToken}/${code}`)
}

// 获取物流的地址
export const apiTransportAreasByLevel = (level, parentId) => {
  return $http.post(`${API}transport/getTransportAreasByLevel`, { level: level, parentId: parentId })
}

// 商品管理
export const apiGoods = {
  // 取消审核中的商品
  updateStatus(data) {
    return $http.post(`${API}goods/updateStatus`, data)
  },
  // 获取供应商名称与机构号
  getSellerInfo(accessToken) {
    return $http.post(`${API}goods/getSellerInfo`, accessToken)
  },
  // 获取平台预设，商家自设的商品基本信息
  getProductParam(data) {
    return $http.post(`${API}goods/getProductParam`, data)
  },
  // 获取商品分类
  getGoodsClassInfo(gcId) {
    return $http.post(`${API}goods/getGoodsClassInfo`, gcId)
  },
  // 商品新增第一步
  goodsInsertFirst(data) {
    return $http.post(`${API}goods/goodsInsertFirst`, data)
  },
  // 商品品牌
  queryGoodsBrand(data) {
    return $http.post(`${API}goods/queryGoodsBrand`, data)
  },
  // 运费模板
  queryGoodsTranSport(data) {
    return $http.post(`${API}goods/queryGoodsTranSport`, data)
  },
  // 获取商品规格
  getSpecifications(data) {
    return $http.post(`${API}goods/getSpecifications`, data)
  },
  // 新增分类下的规格
  insertSpecificationsByGcId(data) {
    return $http.post(`${API}goods/insertSpecificationsByGcId`, data)
  },
  // 查询规格属性
  getSpecproperty(data) {
    return $http.post(`${API}goods/getSpecproperty`, data)
  },
  // 查询颜色尺码
  getPtysProperty() {
    return $http.post(`${API}goods/queryProperty`, {})
  },
  // 新增规格属性
  insetSpecproperty(data) {
    return $http.post(`${API}goods/insetSpecproperty`, data)
  },
  // 删除规格属性
  deleteSpecpropertyById(data) {
    return $http.post(`${API}goods/deleteSpecpropertyById`, data)
  },
  // 图片上传
  goodsSwfUpload(data) {
    return new Promise((resolve, reject) => {
      $.ajax({
        type: 'POST',
        url: `${API}goods/uploadGoodsImageThree`,
        timeout : 10000,
        data: data,
        processData: false,
        contentType: false,
        success(result) {
          resolve(result.data)
        }
      })
    })
  },
  // 商品新增第二步
  goodsInsertSecond(data) {
    return $http.post(`${API}goods/goodsInsertSecond`, data)
  },
  // 获取商品列表
  queryGoodsList(data) {
    return $http.post(`${API}goods/queryGoodsList`, data)
  },
  // 获取未发起拼单商品列表
  queryPdGoodsList(data) {
    return $http.post(`${API}goods/queryPdGoodsList`, data)
  },
  // 商品的上下架 operateType: 0-上架，-1为下架
  goodsGroundUnderCar(operateType, goodsIds, storeId) {
    if (storeId && storeId != null && storeId != undefined && storeId != '') {
      return $http.post(`${API}goods/goodsGroundUnderCar`, { operateType: operateType, goodsIds: goodsIds, storeId: storeId })
    } else {
      return $http.post(`${API}goods/goodsGroundUnderCar`, { operateType: operateType, goodsIds: goodsIds})
    }
  },
  // 删除商品
  deleteGoods(goodsIds, storeId, data) {
    if (data) {
      return $http.post(`${API}goods/goodsdelete`, data)
    } else {
      return $http.post(`${API}goods/goodsdelete`, { goodsIds: goodsIds })
    }
  },
  // 获取商品详情
  goodsInsertSeconds(goodsId) {
    return $http.post(`${API}goods/queryGoodsById`, { goodsId: goodsId })
  },
  // 提交商品详情（编辑接口）
  submitTextContent(data) {
    return $http.post(`${API}goods/goodsEdit`, data)
  },
  // 删除图片地址
  deleteGoodsImg(data) {
    return $http.post(`${API}goods/deleteGoodsImage`, data)
  },
   // 查询规格
  queryGoodstypeproperty(id) {
    return $http.post(`${API}goods/queryGoodstypeproperty`, {gcId: id})
  },
  // 新增商品,和更新商品
  saveGoods(params) {
    return $http.post(`${API}goods/addGood`, { ...params })
  },
  // 商品查询
  queryGoodsDetail(accessToken, id) {
    return $http.post(`${API}goods/queryGoodsInfoById`, { accessToken, id })
  },
  // 保存到草稿箱
  saveSektch(params) {
    return $http.post(`${API}draft/saveGoodsDraft`, { ...params })
  },
  // 删除草稿箱
  deleteSektch(accessToken, ids, goodsStoreId = null) {
    return $http.post(`${API}draft/deleteGoodsDraft`, { accessToken, ids, goodsStoreId })
  },
  // 查询草稿箱里的内容
  querySektch(accessToken, id = '8') {
    return $http.post(`${API}draft/getEditGoodsDraft`, { accessToken, id })
  }
} 
// E电宝导入中的获取商家E电宝秘钥信息,根据商家ID
// goods/edbImport
export const apiGetStoreEdbInfo = (storeId) => {
  return $http.post(`${API}edb/getStoreEdbInfo`, {storeId: storeId})
}
// E电宝导入
export const apiEdbImport = (params) => {
  return $http.post(`${API}goods/edbImport`, params)
}

// 拼单管理
export const apiFight = {
  // 拼单列表查看
  getGoodsCrowdFundRules(data) {
    return $http.post(`${API}goods/getGoodsCrowdFundRules`, data)
  },
  // 单个拼单规则修改接口
  editCrowdFundRule(data) {
    return $http.post(`${API}goods/editCrowdFundRule`, data)
  },
  // 商品拼单规则新增及再次发起拼单
  installCrowdFundRule(data) {
    return $http.post(`${API}goods/installCrowdFundRule`, data)
  },
  // 设置拼单
  getGoodsGspDetail(goodsId) {
    return $http.post(`${API}goods/getGoodsGspDetail`, { goodsId })
  }
}

// 物流管理
export const apiCarriage = {
  // 查询商家的物流模板
  getTransportList(accessToken) {
    return $http.post(`${API}transport/getTransportList`, { accessToken: accessToken })
  },
  // 获取前2级节点
  getTransportAreasForLevel2() {
    return $http.post(`${API}transport/getTransportAreasForLevel2`)
  },
  // 获取物流区域的3级节点
  getTransportAreasByLevel(level, parentId) {
    return $http.post(`${API}transport/getTransportAreasByLevel`, { level: level, parentId: parentId })
  },
  // 新增物流模板
  addTransport(params) {
    return $http.post(`${API}transport/addTransport`, params)
  },
  // 编辑物流模板
  editTransport(params) {
    return $http.post(`${API}transport/updateTransport`, params)
  },
  // 删除物流模板
  deleteTransport(id, accessToken) {
    return $http.post(`${API}transport/deleteTransport`, { id: id, accessToken })
  }
}

// 评论管理的所有接口
export const apiEvalute = {
  // 查询商家的所有商品的评价
  getEvaluteList(accessToken, currentPage, pageSize) {
    return $http.post(`${API}evalute/getEvaluteList`, { accessToken: accessToken, pageSize: pageSize, currentPage: currentPage })
  },

  // 设置评价是否可见
  setEvaluateVisable(id, evaluateStatus, accessToken) {
    return $http.post(`${API}evalute/setEvaluateVisable`, { id: id, evaluateStatus: evaluateStatus, accessToken: accessToken })
  }
}

// 退款管理的所有接口
export const apiRefund = {
  // 获取退款列表
  getRefundList(params) {
    return $http.post(`${API}refund/getRefundList`, params)
  },

  // 审核拒绝
  refuse(id, orderId, reason, accessToken) {
    return $http.post(`${API}refund/refuse`, { accessToken: accessToken, id: id, orderId: orderId, auditFailReason: reason })
  },

  // 审核通过
  pass(id, orderId, accessToken) {
    return $http.post(`${API}refund/pass`, { accessToken: accessToken, id: id, orderId: orderId})
  }
}

// 订单管理界面
export const apiOrder = {
  // 设置拼单结果
  apiControlCrowdFund(data) {
    return $http.post(`${API}order/controlCrowdFund`, data)
  },
  // 普通订单列表
  apiGetCommOrderList(data) {
    return $http.post(`${API}order/getCommOrderList`, data)
  },
  // 拼单订单列表
  apiOrderList(data) {
    return $http.post(`${API}order/getOrderList`, data)
  },
  // 修改发货方
  apiAlterConsignor(data) {
    return $http.post(`${API}order/alterConsignor`, data)
  },
  // 订单详情
  getOrderDetail(id) {
    return $http.post(`${API}order/getOrderDetail`, { id: id })
  },
  // 打印订单
  printOrder(id) {
    return $http.post(`${API}order/printOrder`, { id: id })
  },
  comfireDelivery(orderId, shipCode, message, accessToken) {
    return $http.post(`${API}order/confirmDelivery`, { id: orderId, shipCode: shipCode, storeSelfMsg: message, accessToken: accessToken })
  },
  // 修改价格
  updatePrice(params) {
    return $http.post(`${API}order/updatePrice`, params)
  }
}

// 获取商家信息（首页）
export const apiHomeStoreInfo = (accessToken) => {
  return $http.post(`${API}home/getStoreInfo`, { accessToken: accessToken })
}

// 店铺装修PC
export const apiAdornPC = {
  // 获取导航列表
  getNavigationList(accessToken) {
    return $http.post(`${API}decoration/getNavigationList`, { accessToken: accessToken, decorationType: 'PC' })
  },
  // 搜索商品列表
  searchGoodsByParams(params) {
    return $http.post(`${API}decoration/searchGoods`, params)
  },
  // 新增导航
  addNavigation(params) {
    return $http.post(`${API}decoration/addNavigation`, params)
  },
  // 编辑导航
  editNavigation(params) {
    return $http.post(`${API}decoration/updateNavigation`, params)
  },
  // 删除导航
  deleteNavigation(id, accessToken) {
    return $http.post(`${API}decoration/deleteNavigation`, { id: id, accessToken: accessToken })
  },
  // 获取楼层列表
  getFloorList(decorationType, accessToken) {
    return $http.post(`${API}decoration/getFloorList`, { decorationType: 'PC', accessToken: accessToken })
  },
  // 添加楼层
  addFloor(params) {
    return $http.post(`${API}decoration/addFloor`, params)
  },
  // 删除楼层
  deleteFloor(id, token, decorationType) {
    return $http.post(`${API}decoration/deleteFloor`, { accessToken: token, id: id, decorationType: decorationType })
  },
  // 颜色
  saveColor(accessToken, colorStyle) {
    return $http.post(`${API}decoration/saveNavigation`, { accessToken: accessToken, decorationType: 'PC', colorStyle: colorStyle })
  },
  // 保存楼层信息
  saveFloor(params) {
    return $http.post(`${API}decoration/saveFloor`, params)
  },
  // 修改所有宝贝 是否显示
  apiUpdateShowAllGoods(accessToken, isOpen, decorationType) {
    return $http.post(`${API}decoration/updateShowAllGoods`, { accessToken, isOpen, decorationType })
  }
}

// 店铺装修WAP
export const apiAdornWAP = {
  // 获取楼层列表
  getFloorList(decorationType, accessToken) {
    return $http.post(`${API}decoration/getFloorList`, { decorationType: 'WAP', accessToken: accessToken })
  },
  // 获取导航列表
  getNavigationList(accessToken) {
    return $http.post(`${API}decoration/getNavigationList`, { accessToken: accessToken, decorationType: 'WAP' })
  },
  // 搜索商品列表
  searchGoodsByParams(params) {
    return $http.post(`${API}decoration/searchGoods`, params)
  },
  // 新增导航
  addNavigation(params) {
    return $http.post(`${API}decoration/addNavigation`, params)
  },
  // 编辑导航
  editNavigation(params) {
    return $http.post(`${API}decoration/updateNavigation`, params)
  },
  // 删除导航
  deleteNavigation(id, accessToken) {
    return $http.post(`${API}decoration/deleteNavigation`, { id: id, accessToken: accessToken })
  },
  // 修改所有宝贝 是否显示
  apiUpdateShowAllGoods(accessToken, isOpen, decorationType) {
    return $http.post(`${API}decoration/updateShowAllGoods`, { accessToken, isOpen, decorationType })
  }
}

// 获取数据字典项
export const apiDictionaryByName = (typeName) => {
  return $http.post(`${API}dictionary/getDictionaryByName`, { typeName: typeName })
}

// 同步本店铺数据到平台
export const apiSendDataToRemote = (params) => {
  return $http.post(`${API_SEARCH}lucene/createUpdateIndex`, params)
}

// 删除本店铺数据到平台
export const apiDeleteDataToRemote = (params) => {
  return $http.post(`${API_SEARCH}lucene/deleteLucene`, params)
}

// 删除或下架商品后更新索引
export const apiUpdateLucenceByDelete = (storeId) => {
  return $http.post(`${API_SEARCH}lucene/createUpdateIndex`, { searchType: 'store', storeId: storeId })
}

// 聊天 发送消息
export const apiChatSendMsg = params => {
  return $http.post(`${API_FRONT}chat/sendMessage`, { ...params })
}

export const apiCount = {
  // 新增银行卡
  addBankCard(data) {
    return $http.post(`${API_FRONT}bank/addBankCard`, data)
  },
  // 查询银行卡
  showBandCardAll(accessToken, currentPage, showCount) {
    return $http.post(`${API_FRONT}bank/showBandCardAll`, {accessToken: accessToken, currentPage: currentPage, showCount: showCount})
  },
  // 根据id查询银行卡信息
  showBankCard(id) {
    return $http.post(`${API_FRONT}bank/showBankCard`, id)
  },
  // 根据id删除银行卡信息
  deleteBankCard(id,accessToken) {
    return $http.post(`${API_FRONT}bank/deleteBankCard`, {id: id, accessToken: accessToken})
  },
  // 修改银行卡信息
  editBankCard(data) {
    return $http.post(`${API_FRONT}bank/editBankCard`, data)
  },
   // 修改银行卡信息
  showBankName(accessToken) {
    return $http.post(`${API_FRONT}bank/showBankName`, { accessToken: accessToken })
  }
}

// 订单管理模块
export const apiOrderMange = {
  // 普通订单导出功能
  apiOrderExport(params) {
    return $http.get(`${API4}orderform/YouzhengOrderform/exportRefundOrder`, params)
  },
  // 获取订单列表: 获取普通订单，拼单主订单列表
  apiOrderListAll(params) {
    return $http.post(`${API4}orderform/YouzhengOrderform/getOrderFormList`, params)
  },
  // 拼单列表--子订单列表数据
  apiFOrderList(params) {
    return $http.post(`${API4}orderform/YouzhengOrderform/getFightChilds`, params)
  },
  // 拼单列表--主订单详情
  apiFMOrderInfo(accessToken, goodsRuleId) {
    return $http.post(`${API4}orderform/YouzhengOrderform/mainOrderDetails`, { accessToken, goodsRuleId })
  },
  // 拼单列表--主订单详情--设置拼单结果:isAlready: 1,成功，0，失败
  apiFMOrderUpdateStatus(accessToken, goodsRuleId, isAlready) {
    return $http.post(`${API4}orderform/YouzhengOrderform/updateCollageStatus`, { accessToken, goodsRuleId, isAlready })
  },
  // 拼单子订单导出
  apiFOrderExport(params) {
    return $http.get(`${API4}orderform/YouzhengOrderform/exportFightChilds`, params)
  },
  // 获取订单详情
  apiCOrderInfo(accessToken, ofId) {
    return $http.post(`${API4}orderform/YouzhengOrderform/getOrderDetails`, { accessToken, ofId })
  },
  // 获取退款订单详情
  apiReOrderInfo(accessToken, reId) {
    return $http.post(`${API4}orderform/YouzhengOrderform/getRefundOrderDetails`, { accessToken, reId })
  },
  // 免运费操作
  apiCOrderListFree(accessToken, ofIds) {
    return $http.post(`${API4}orderform/YouzhengOrderform/freeFreight`, { accessToken, ofIds })
  },
  // 改价
  apiChangeGoodsPrice(params) {
    return $http.post(`${API4}orderform/YouzhengOrderform/alterOrderFormPrice`, params)
  },
  // 发货
  apiDeliveryGoods(params) {
    return $http.post(`${API4}orderform/YouzhengOrderform/delivOrderForm`, params)
  },
  // 修改发货方
  apiEditConsigor(ofId, consignor) {
    return $http.post(`${API4}orderform/YouzhengOrderform/editConsignor`, { ofId, consignor })
  },
  // 延长收货时间，商家备忘，修改订单商品属性, 退款审核
  apiDeliveryGoodsFar(params) {
    return $http.post(`${API4}orderform/YouzhengOrderform/updateOrderDetails`, params)
  },
  // 查询订单中商品是否在售
  apiGoodsStatus(ids) {
    return $http.post(`${API4}orderform/YouzhengOrderform/checkGoodsSoldOut`, { ids })
  },
  // 查询好下单提醒
  apiRemindMessage(accessToken, ofId, type = 1) {
    return $http.post(`${API4}orderform/YouzhengOrderform/remindMessage`, { accessToken, ofId, type })
  },
  // 查询物流详情
  apiExpressInfo(accessToken, ofId, shipCode = null) {
    return $http.post(`${API4}express/Express/getExpressInfoByOrderId`, { accessToken, ofId, shipCode })
  },
  // 获取退款订单列表
  apiRefundOrderList(params) {
    return $http.post(`${API4}orderform/YouzhengOrderform/getRefundList`, params)
  }
}
